package com.welsmann.app.start.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.welsmann.app.start.common.StartUtil;
import com.welsmann.app.start.dao.IHolidayDAO;
import com.welsmann.app.start.entity.Holiday;
import com.welsmann.app.start.service.BaseService;
import com.welsmann.app.start.service.IHolidayService;

/**
 * 假日服务层
 * 
 * @author Welsmann
 * 
 */
@Service("HolidayService")
@Transactional(readOnly = true)
public class HolidayService extends BaseService implements IHolidayService {

	@Resource(name = "HolidayDAO")
	private IHolidayDAO holidayDAO;

	@Override
	public String getHolidayByDate(int month, int day) {
		String result = "";
		if (StartUtil.isValidMonthAndDay(month, day)) {
			List<Holiday> lstHoliday = holidayDAO.getHolidayByDate(month, day);
			result = String.format("今天是%s月%s日，%s", month, day,
					StartUtil.getWeekName());
			if (lstHoliday != null && !lstHoliday.isEmpty()) {
				Holiday holiday = lstHoliday.get(0);
				result += String.format("，%s", holiday.getTitle());
			}
		}
		return result;
	}

	@Override
	public List<Holiday> getAll() {
		return holidayDAO.getAll();
	}

}
